package CAS;

import java.util.concurrent.atomic.AtomicInteger;

public class 博客 {
    //public static volatile int count = 0;
    public static AtomicInteger t = new AtomicInteger(0);
    private static final int arr_length = 20;

    public static  void increase(){
        t.getAndIncrement();
    }

    public static void main(String[] args) {
        Thread[] threads = new Thread[arr_length];
        for (int i = 0; i < arr_length; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0; j < 10000; j++) {
                        increase();
                    }
                }
            });
            threads[i].start();
        }
        while (Thread.activeCount() > 1){
            Thread.yield();
        }
        System.out.println(t.get());
    }
}
